import hashlib,time

def get_sign(url):
	md5 = hashlib.md5()
	md5.update(url.encode('utf-8'))
	return md5.hexdigest().lower()

def get_md5(data, key):
    data_keys = data.keys()

    url = ""
    for idx,k in enumerate(sorted(data_keys)):
        if idx != 0:
            url += "&" + k + "=" + str(data[k])
        else :	
            url += k + "=" + str(data[k])   
    url += "&key=" + key
    print(url)
    sign = get_sign(url)    
    return sign

def main():
    # data = {
    #    "tx" : int(time.time()),
    #     "uid" : 52573,
    #     "gap" : 300,
    #     "app_id":6,
       
    #     # "commodityId" : "INR500",
    #     # 'outOrderNo' : "81607831259886052573805013",
    #     # 'outPayAmount' : "33.00",
    #     # 'exchangeRate' : "22.00",
    #     # 'amountDollar' : "11.00",
    #     # 'realAmount' : "10.00",
    #     # 'channelCode' : "RVG1S03S",
    # }
#     data = {
#        "amount" : 100,
#         "currency" : "INR",
#         "code" : 0,
#         "orderId" : "202012161108429054044120",
#         "merchantId" : "10096",
#         "appId" : "100000152",
#         "outUserId" : 52573,
#         "passageTradeNo" : "xxxxxx",
#         "successTime" : "2020-12-16 10:18:22",
#         # "sign":"5c1a4f6bbffe4400c5b422bd0a1564db"
# }

    data = {
        'app_id':'10001',
        'tx':'1608827583',
        'uid':'52592',
        'gap':300,
    }

    sign = 'd441c56f1ea025a958f6c92e9e1d8a7b'
    s = get_md5(data, sign)

    print(s)

if __name__ == "__main__":
    main()